package com.neu.emp;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;




/**
	 * 
	 * @author neustu
	 *   通过jdbc完成对emp表的数据更新，更新员工编号为7782，
	 *              更新数据（ename：赵四 ，job： manager ，mgr 7782 ）；
	 */
public class Demo03 {
	private static String url = "jdbc:mysql://localhost:3306/mjq";
	private static String userName = "root";
	private static String pass = "mysql";
	private static String driver = "com.mysql.jdbc.Driver";
	public static Connection conn;
	public static PreparedStatement ps;
	static {
		try {
		//  驱动的加载   对应的方法是    Class.forName(driver);
			//  先生成下面的代码   然后快捷生成  try{}
			Class.forName(driver);
			//  生成    Connection 对象
			conn=DriverManager.getConnection(url,userName,pass);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	} 
	
	public static boolean update(String a,String b,int c,int d) throws SQLException {
		boolean flag = false;
		String sql = "update tb_emp set ename=?,job=?,mgr=? where empno=?";
		ps= conn.prepareStatement(sql);
		ps.setString(1,a);
		ps.setString(2,b);
		ps.setInt(3, c);
		ps.setInt(4, d);
		int e = ps.executeUpdate();
		if(e>0) {
			flag = true;
		}
		return flag;
	}

	public static void main(String[] args) throws SQLException {
	update("赵四",  "manager", 7782, 7782);

	}

}
